/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			prpex_enum.cc
  \date			june 2011
  \author		TNick

  \brief		string class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read ReadMe.txt and Licence.txt in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QComboBox>

#include	"prpmdl.h"
#include	"prpview.h"
#include	"prpex_enum.h"

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  FUNCTIONS    ----------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
PEX_Enum::PEX_Enum	(
		PrpMdl*		pa_mdl,		/**< father model */
		PrpNode*	pa_fth,		/**< father item; NULL for top level */
		QString		stra_name,	/**< name of entry */
		QString		stra_descr,	/**< description of entry */
		unsigned	init_idx,	/**< index of initally selected entry */
		QStringList	ql_init		/**< list of enumeated values */
		)

			: PrpTpl(pa_mdl, pa_fth, PrpTpl::ENUM, stra_name, stra_descr)
{
	qsl_enum = ql_init;
	i_index = init_idx;
	iconDec(true);
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
QWidget*	PEX_Enum::editCreate	(QWidget *parent, const QStyleOptionViewItem &option)
{
	Q_UNUSED(option);
	QComboBox *editor = new QComboBox(parent);
	editor->addItems(qsl_enum);
	return editor;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void		PEX_Enum::editLoad	(QWidget *editor)
{
	QComboBox*	qcbx = static_cast<QComboBox*>(editor);
	qcbx->setCurrentIndex(i_index);
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void		PEX_Enum::editSave	(QWidget *editor)
{
	QComboBox*	qcbx = static_cast<QComboBox*>(editor);
	i_index = qcbx->currentIndex();
	informParent();
}
/* ========================================================================= */


/* ------------------------------------------------------------------------- */
bool		PEX_Enum::changeVal	(QVariant new_value)
{



	return false;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void		PEX_Enum::editIcon	(PrpView * prp_v, QModelIndex the_idx)
{

	PrpMdl* mdl = static_cast<PrpMdl*>(prp_v->model());
	if (qsl_enum.count() == 0)
		return;
	i_index++;
	if (i_index >= qsl_enum.count())
		i_index = 0;
	informParent();
	mdl->dataHasChanged(the_idx);

}
/* ========================================================================= */

/*  FUNCTIONS    =========================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
